/*
 * test_shm2.cpp
 *
 *  Created on: Apr 23, 2014
 *      Author: killerg
 */


#include "share/util.h"

static char buffer[100];
bool test_shm2(int type) {

	if (type > 1) {
		char* mem = (char*)shm_new("/test_shm2", sizeof(buffer));
		if (!mem) {
			perror("shm_new");
			return false;
		}

		for (int j=0; j<1000000; ++j) {
			for (int i=0; i<100; ++i) {
				mem[i] = '0' + j % 10;
			}
			sleep(1);
		}

		shm_free("/test_shm2", sizeof(buffer), mem);
	} else {
		char* mem = (char*)shm_get("/test_shm2", sizeof(buffer));
		if (!mem) {
			perror("shm_get");
			return false;
		}

		shm_free("/test_shm2", sizeof(buffer), mem);
		return true;
	}


	return true;
}
